package com.gzsxy.esjy.message.mds.handler;


import com.gzsxy.esjy.message.mds.dto.MdsMessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * mds处理
 */
@Slf4j
public class MdsHandler extends SimpleChannelInboundHandler<MdsMessage> {

    private static final String HEARTBEAT = "heartbeat";

    private final String mds ;

    public MdsHandler(String mds) {
        this.mds = mds;
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MdsMessage msg) throws Exception {
        //处理心跳
        String cmd = msg.getCommand() ;
        if(cmd.equalsIgnoreCase(HEARTBEAT)) {
            log.debug("接收到来自于 {} 的心跳信息 ",ctx.channel().toString());
            ctx.channel().writeAndFlush(MdsMessage.heartbeat("response",msg.getSessionId())) ;
            return ;
        }
    }

}
